package com.renwei.yunlong.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.renwei.yunlong.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Project :  yunaandroid.
 * Package name: com.renwei.yunlong.adapter
 * Created by :  Benjamin.
 * Created time: 2017/11/7 17:54
 * Changed by :  Benjamin.
 * Changed time: 2017/11/7 17:54
 * Class description:
 */

public class LevelListAdapter extends RecyclerView.Adapter<LevelListAdapter.ViewHolder> {
    private List<String> arry;
    private Context context;
    LevelChangeListener levelChangeListener;

    public interface LevelChangeListener {
        void click(int position, String name);
    }


    public void setLevelChangeListener(LevelChangeListener levelChangeListener) {
        this.levelChangeListener = levelChangeListener;
    }

    public LevelListAdapter(Context context) {
        this.context = context;
        this.arry = new ArrayList<>();
        arry.add("无等级");
        arry.add("五级");
        arry.add("四级");
        arry.add("三级");
        arry.add("二级");
        arry.add("一级");
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_level, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        if (holder != null) {
            holder.text.setText(arry.get(position));
            holder.text.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    levelChangeListener.click(position,arry.get(position));
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return arry.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView text;

        public ViewHolder(View itemView) {
            super(itemView);
            text = itemView.findViewById(R.id.tv_level);
        }
    }
}
